package edu.pw.p2pclient.networking.messages;

import edu.pw.p2pclient.data.Node;
import edu.pw.p2pclient.data.ResourcePart;

public class ResourcePartResponse extends Message {

	private static final long serialVersionUID = -8259254261175058276L;

	private int mError; // 1 - wrong password, 2 - denied, 3 - Unknown
	private Node mResource;
	private ResourcePart mPart;

	public ResourcePartResponse(int error) {

		super(MsgType.RESOURCE_PART_RESPONSE);
		mError = error;
		mResource = null;
		mPart = null;
	}

	public ResourcePartResponse(Node resource, int part) {

		super(MsgType.RESOURCE_PART_RESPONSE);
		mError = 0;
		mResource = resource;
		try {
			mPart = new ResourcePart(resource.getFullPath(), part);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public int getError() {
		return mError;
	}

	public Node getResource() {

		return mResource;
	}

	public int getPart() {

		return mPart.getPartNum();
	}

	public byte[] getData() {

		return mPart.getRaw();
	}

}
